package karileet.meeting.profile.fragment;

import karileet.meeting.profile.ProfileConf;
import karileet.meeting.profile.list.holder.ListCheckboxItemHolder;
import karileet.meeting.profile.list.item.ListCheckboxItem;
import karileet.meeting.profile.model.ThirdParty;

import java.util.ArrayList;
import java.util.List;

/**
 * List shows all available third party applications that meeting profile can use via accessibility option
 */
public class ThirdPartyListFragment extends AbstractListFragment {

    @Override
    protected void onClickAction(ListCheckboxItemHolder holder, int position) {
        ProfileConf conf = new ProfileConf(getActivity());
        ThirdParty tp = conf.getThirdPartyApps();
        // pass isChecked directly, since it is toggled in abstract class already!
        tp.set(holder.getTag().getDescription(), holder.getCb().isChecked());
        conf.setThirdPartyApps(tp);
    }

    protected List<ListCheckboxItem> populateMainList() {
        ProfileConf conf = new ProfileConf(getActivity());
        ThirdParty tp = conf.getThirdPartyApps();
        int id = 0;
        List<ListCheckboxItem> list = new ArrayList<ListCheckboxItem>();
        for (java.util.Map.Entry<String, Boolean> set : tp.getApps().entrySet()) {
            id = getResources().getIdentifier(set.getKey(), "string", "karileet.meeting.profile");
            String value = id == 0 ? "" : (String) getResources().getText(id);
            list.add(new ListCheckboxItem(value, set.getKey(), set.getValue()));
        }

        return list;
    }
}
